package me.send.produce.data.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import me.send.business.base.Pager;
import me.send.data.service.pojo.base.DatatablesViewPage;
import me.send.data.service.service.OrdersService;
import me.send.data.service.service.TreeService;
import me.send.produce.data.controller.common.CommonController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "orders")
public class OrdersController extends CommonController {

	@Autowired
	private OrdersService ordersService;

	@Autowired
	private TreeService treeService;
	
	
	@RequestMapping(value = "order/list")
	public ModelAndView order_list(HttpServletRequest request) {
		// 增加一个连接 2015年6月19日16:57:02
		
		// 如果这个连接 和 树里面的链接是一样的 那就替换一下
		
		ModelAndView modelAndView = new ModelAndView(
				"stage/orders/order_list");
		modelAndView.addObject("LoadTree",  treeService.main_tree(0, request, "orders/order/list"));
//		session.setAttribute("LoadTree",  treeService.main_tree(0, request, "orders/order/list"));
		
		modelAndView.addObject("module", "订单列表");
		return modelAndView;
	}

//	@RequestMapping(value = "order/page")
//	@ResponseBody
//	public Map<String, Object> orders_page(Pager page,Orders orders) {
//		return ordersService.orders_page(page,orders);
//	}
	
	@RequestMapping(value = "order/data")
	@ResponseBody
	public DatatablesViewPage<Map<String, Object>> ordersData(HttpServletRequest request, Integer otype, Integer ostatus,String keyCode) {
		DatatablesViewPage<Map<String, Object>> vp = new DatatablesViewPage<Map<String, Object>>();
		try {
			//获取分页控件的信息  
			String start = request.getParameter("start");  
			String length = request.getParameter("length"); 
			Pager page=new Pager();
			Integer row=Integer.parseInt(length);
			page.setRows(row);
			Integer startInt=Integer.parseInt(start);
			Integer p=(startInt/row)+1;
			page.setPage(p);
			int count = ordersService.ordersCount(otype, ostatus, keyCode);
			List<Map<String, Object>> data = ordersService.ordersData(page, otype, ostatus, keyCode);
			vp.setAaData(data);
			vp.setiTotalDisplayRecords(count);
			vp.setiTotalRecords(count);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vp;
	}
	
	

	@RequestMapping(value = "deletes")
	@ResponseBody
	public Map<String, Object> deletes(String orderids) {
		// 返回 2015年6月18日18:17:54
		return ordersService.deletes(orderids);
	}
}
